package com.dwk.rabbitMQ2;

import com.dwk.utils.RabbitMqUtils;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

/**
 * 这是一个工作线程（相当于消费者）
 */
public class Worker01 {
    private final static String QUEUE_NAME = "hello";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();

        //消息的接收
        DeliverCallback deliverCallback=(consumerTag, message) ->{
            System.out.println(new String(message.getBody()));
        };

        CancelCallback cancelCallback= var1 ->{
            System.out.println("消息消费被中断");
        };

        //消费者接收消息
        System.out.println("C2等待接收消息.....");
        channel.basicConsume(QUEUE_NAME,true,deliverCallback,cancelCallback );
    }
}
